////
////  BiAddressPicker.m
////  GottaWash
////
////  Created by bindu on 14-8-20.
////  Copyright (c) 2014年 QiHe. All rights reserved.
////
//
//#import "BiAddressPicker.h"
//#import "BiDBManager.h"
//#import "BiLevel1AddressEntity.h"
//#import "BiLevel2AddressEntity.h"
//
//#define kDuration 0.3
//
//@interface BiAddressPicker()<UIPickerViewDelegate, UIPickerViewDataSource>
//{
//    UIPickerView * _addressPicker;
//}
//@property (nonatomic, retain) NSMutableArray * level1AddressArray;
//@property (nonatomic, retain) NSMutableArray * level2AddressArray;
//@end
//
//@implementation BiAddressPicker
//@synthesize level1AddressStr;
//@synthesize level2AddressStr;
//
//- (id)init
//{
//    self = [super initWithFrame:CGRectMake(0, 0, MAIN_SCREEN_WIDTH, 216+44)];
//    if (self)
//    {
//        self.level1AddressArray = [NSMutableArray array];
//        self.level2AddressArray = [NSMutableArray array];
//        
//        NSArray * level1AddressArray = [[BiDBManager shareInstance] getLevel1AddressArray];
//        if (nil != level1AddressArray)
//        {
//            [self.level1AddressArray addObjectsFromArray:level1AddressArray];
//        }
//        
//        if (self.level1AddressArray.count > 0)
//        {
//            BiLevel1AddressEntity * level1AddressEntity = [self.level1AddressArray objectAtIndex:0];
//            self.level1AddressStr = level1AddressEntity.name;
//            
//            NSArray * level2AddressArray = [[BiDBManager shareInstance] getLevel2AddressArrayByLevel1ServerId:level1AddressEntity.server_id];
//            if (nil != level2AddressArray)
//            {
//                [self.level2AddressArray addObjectsFromArray:level2AddressArray];
//            }
//        }
//        if (self.level2AddressArray.count > 0)
//        {
//            BiLevel2AddressEntity * level2AddressEntity = [self.level2AddressArray objectAtIndex:0];
//            self.level2AddressId = level2AddressEntity.server_id;
//            self.level2AddressStr = level2AddressEntity.name;
//        }
//        
//        // Initialization code
//        UIView * topBgView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, MAIN_SCREEN_WIDTH, 44)];
//        topBgView.backgroundColor = [UIColor grayColor];
//        [self addSubview:topBgView];
//        [topBgView release];
//        
//        UIButton * completeBtn = GET_BUTTON(CGRectMake(MAIN_SCREEN_WIDTH-60, 1, 60, 42), 15, NO, [UIColor whiteColor]);
//        [completeBtn addTarget:self action:@selector(onCompleteBtnClick:) forControlEvents:UIControlEventTouchUpInside];
//        [completeBtn setTitle:@"完成" forState:UIControlStateNormal];
//        [self addSubview:completeBtn];
//        
//        _addressPicker = [[UIPickerView alloc] initWithFrame:CGRectMake(0, 44, MAIN_SCREEN_WIDTH, 216)];
//        _addressPicker.delegate = self;
//        _addressPicker.dataSource = self;
//        
//        [self addSubview:_addressPicker];
//        [_addressPicker release];
//    }
//    
//    return self;
//}
//
//- (void)showInView:(UIView *) view
//{
//    CATransition *animation = [CATransition  animation];
//    animation.delegate = self;
//    animation.duration = kDuration;
//    animation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
//    animation.type = kCATransitionPush;
//    animation.subtype = kCATransitionFromTop;
//    [self setAlpha:1.0f];
//    [self.layer addAnimation:animation forKey:@"DDAddressPickerView"];
//    
//    self.frame = CGRectMake(0, view.frame.size.height - self.frame.size.height, self.frame.size.width, self.frame.size.height);
//    
//    [view addSubview:self];
//}
//
//- (void)dealloc
//{
//    self.level1AddressArray = nil;
//    self.level2AddressArray = nil;
//    
//    [super dealloc];
//}
//
//#pragma mark - PickerView lifecycle
//- (NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView
//{
//    return 2;
//}
//
//- (CGFloat)pickerView:(UIPickerView *)pickerView widthForComponent:(NSInteger)component
//{
//    CGFloat componentWidth = 0.0;
//    
//    if (component == 0)
//    {
//        componentWidth = 120.0; // 第一个组键的宽度
//    }
//    else
//    {
//        componentWidth = 200.0; // 第2个组键的宽度
//    }
//    
//    return componentWidth;
//}
//
//- (NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component
//{
//    switch (component)
//    {
//        case 0:
//            return self.level1AddressArray.count;
//            break;
//        case 1:
//            return self.level2AddressArray.count;
//            break;
//        default:
//            return 0;
//            break;
//    }
//}
//
//- (NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component
//{
//    switch (component)
//    {
//        case 0:
//        {
//            BiLevel1AddressEntity * level1AddressEntity = [self.level1AddressArray objectAtIndex:row];
//            return level1AddressEntity.name;
//        }
//            break;
//        case 1:
//        {
//            BiLevel2AddressEntity * level2AddressEntity = [self.level2AddressArray objectAtIndex:row];
//            return level2AddressEntity.name;
//        }
//            break;
//        default:
//            return nil;
//            break;
//    }
//}
//
//- (void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component {
//    switch (component)
//    {
//        case 0:
//        {
//            BiLevel1AddressEntity * level1AddressEntity = [self.level1AddressArray objectAtIndex:row];
//            self.level1AddressStr = level1AddressEntity.name;
//            NSLog(@"%@", self.level1AddressStr);
//            
//            NSArray * tmpLevel2AddressArray = [[BiDBManager shareInstance] getLevel2AddressArrayByLevel1ServerId:level1AddressEntity.server_id];
//            [self.level2AddressArray removeAllObjects];
//            if (nil != tmpLevel2AddressArray)
//            {
//                [self.level2AddressArray addObjectsFromArray:tmpLevel2AddressArray];
//                
//                BiLevel2AddressEntity * level2AddressEntity = [self.level2AddressArray objectAtIndex:0];
//                self.level2AddressId = level2AddressEntity.server_id;
//                self.level2AddressStr = level2AddressEntity.name;
//            }
//            
//            [_addressPicker selectRow:0 inComponent:1 animated:NO];
//            [_addressPicker reloadComponent:1];
//        }
//            break;
//        case 1:
//        {
//            BiLevel2AddressEntity * level2AddressEntity = [self.level2AddressArray objectAtIndex:row];
//            NSLog(@"%@", level2AddressEntity.name);
//            self.level2AddressId = level2AddressEntity.server_id;
//            self.level2AddressStr = level2AddressEntity.name;
//        }
//            break;
//        default:
//            break;
//    }
//}
//
//#pragma mark - Button lifecycle
//- (void)onCompleteBtnClick:(id)sender
//{
//    CATransition *animation = [CATransition  animation];
//    animation.delegate = self;
//    animation.duration = kDuration;
//    animation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
//    animation.type = kCATransitionPush;
//    animation.subtype = kCATransitionFromBottom;
//    [self setAlpha:0.0f];
//    [self.layer addAnimation:animation forKey:@"BiAddressPickerView"];
//    [self performSelector:@selector(removeFromSuperview) withObject:nil afterDelay:kDuration];
//    if(self.delegate)
//    {
//        [self.delegate actionSheet:self clickedButtonAtIndex:1];
//    }
//    
//}
//
//@end
